package com.broada.apm.indicator.api.util;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

/**
 * 
 * 日期反序列化
 * 
 * @author louyi Create By 2014-11-21 上午10:56:20
 */
public class CustomerDateAndTimeDeserialize extends JsonDeserializer<Date> {
	public CustomerDateAndTimeDeserialize(){}
  private SimpleDateFormat dateFormat = new SimpleDateFormat(
          "yyyy-MM-dd'T'HH:mm:ss.SSS");

  @Override
  public Date deserialize(JsonParser paramJsonParser,
          DeserializationContext paramDeserializationContext)
          throws IOException, JsonProcessingException {
      String str = paramJsonParser.getText().trim();
      try {
          return dateFormat.parse(str);
      } catch (ParseException e) {

      }
      return paramDeserializationContext.parseDate(str);
  }
}